function strFormat(str) {
  return str < 10 ? `0${str}` : str
}
// 时间戳转日期
export function timeStamp(time){
  const dates = new Date(time)
  const year = dates.getFullYear()
  const month = dates.getMonth() + 1
  const date = dates.getDate()
  const day = dates.getDay()
  const hour = dates.getHours()
  const min = dates.getMinutes()
  const days = ['日','一','二','三','四','五','六']
  return {
    allDate: `${year}/${strFormat(month)}/${strFormat(date)}`,
    date: `${strFormat(month)}/${strFormat(date)}`,
    day: `周${days[day]}`,
    hour: strFormat(hour) + ':' + strFormat(min)
  }
}
// 获取最近7天的日期和礼拜天数
export function dateData(){
  const time = []
  const date = new Date()
  const now = date.getTime()
  let timeStr = 3600 * 24 * 1000
  for(let i = 0; i < 7; i++){
    const timeObj = {}
    timeObj.date = timeStamp(now + timeStr * i).date
    timeObj.allDate = timeStamp(now + timeStr * i).allDate
    timeObj.timeStamp = now + timeStr * i
    // if(i == 0){
    //   timeObj.week = '今天'
    // }else if(i == 1){
    //   timeObj.week = '明天'
    // }else if(i == 2){
    //   timeObj.week = '后天'
    // }else{
      timeObj.week = timeStamp(now + timeStr * i).day
    // }
    time.push(timeObj)
  }
  return time
}

//时间数组
export function timeData(startTime = '08:00', endTime = '18:30',timeInterval = 0.5){
  const time = []
  const date = timeStamp(Date.now()).allDate
  const startDate = `${date} ${startTime}`
  const endDate = `${date} ${endTime}`
  const startTimeStamp = new Date(startDate).getTime()
  const endTimeStamp = new Date(endDate).getTime()
  const timeStr = 3600 * 1000 * timeInterval
  let count = 0
  for(let i = startTimeStamp; i <= endTimeStamp; i = i + timeStr){
    const timeObj = {}
    timeObj.time = timeStamp(i).hour
    timeObj.disable = 1
    timeObj.index = count
    time.push(timeObj)
    count ++
  }
  return time
}